package xycdao

import (
	"Cgo/front/models"
	"Cgo/global"
)

type xycOrderDao struct{}

var XycOrderDao = new(xycOrderDao)

// 添加订单
func (*xycOrderDao) AddOrderDao(order models.XycOrder) error {
	if err := global.DB.Create(&order).Error; err != nil {
		return err
	}
	return nil
}

// 根据userId查询订单列表
func (*xycOrderDao) FindOrderByUserIdDao(userId int) ([]models.XycOrder, error) {
	var orders []models.XycOrder
	if err := global.DB.Where("user_id = ?", userId).Find(&orders).Error; err != nil {
		return nil, err
	}
	return orders, nil
}
